import http from '../../utils/http'
import type {ApiResponse, PageResult} from '../../utils/ApiResponse'
import {PageProducts, Products} from "./types/products.dto.ts";

// 获取所有商品数据
export const getAllProducts = (data: PageProducts): Promise<PageResult<Object>> => {
    return http.get(`/product/info`, {
        params: {
            page: data.page,
            limit: data.limit,
            productName: data.productName,
            categoryName: data.categoryName,
            status: data.status,
            userId: data.userId
        }
    })
}

// 添加商品
export const addProduct = (data: Products): Promise<ApiResponse<Products>> => {
    return http.post(`/product/save`, data)
}

// 获取商品类别
export const getCategoryList = (): Promise<PageResult<Object>> => {
    return http.get(`/categories/info`)
}

// 获取商品详情
export const getProductInfoById = (id: number): Promise<ApiResponse<Products>> => {
    return http.get(`/product/info/${id}`)
}

// 修改商品
export const saveProductInfo = (data: any): Promise<ApiResponse<Products>> => {
    return http.post(`/product/save`, data)
}

// 删除商品
export const deleteProductById = (id: number): Promise<ApiResponse<Object>> => {
    return http.delete(`/product/delete/${id}`)
}
